//
//  FocusDoctorViewController.m
//  QuickCure
//
//  Created by haoge on 16/9/10.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "FocusDoctorViewController.h"
#import "AttentionDoctorModel.h"
#import "DoctorListCell.h"
#import "DoctorMessageViewController.h"


@interface FocusDoctorViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,weak)UITableView *tableView;
@property (nonatomic,strong)NSArray *doctorList;

@end

@implementation FocusDoctorViewController

- (void)setDoctorList:(NSArray *)doctorList
{
    _doctorList = doctorList;
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //加载模型数据:
    [AttentionDoctorModel doctorListWithSuccess:^(NSArray *array) {
        self.doctorList = array;
    }];
    
    //初始化UI:
    [self setupUI];
    
    //设置返回按钮样式:
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"home_nav_button_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backItemClick)];
}
- (void)backItemClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupUI
{
    //加载医生列表:
    UITableView *tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    self.tableView = tableView;
    [tableView setDataSource:self];
    [self.view addSubview:tableView];
    tableView.rowHeight = 120;
    [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [tableView setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:1]];
    [tableView setDelegate:self];
}

#pragma mark
#pragma mark UItableViewDataSource:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.doctorList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DoctorListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(!cell)
    {
        cell = [[DoctorListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    AttentionDoctorModel *model = self.doctorList[indexPath.row];
    cell.model = model;
    
    return cell;
}

#pragma mark
#pragma mark UITableVeiwDelegate:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    AttentionDoctorModel *model = self.doctorList[indexPath.row];
    DoctorMessageViewController *dmVC = [[DoctorMessageViewController alloc]init];
    dmVC.doctorModel = model;
    
    [self.navigationController pushViewController:dmVC animated:YES];
}

@end

